cc.Class({
    extends: cc.Component,

    properties: {
        label: cc.Node,
    },


    onEnable() {
        this.node.opacity = 0;  //得到服务器返回之前先不显示
        this.lobbyMain = cc.find("Canvas").getComponent("lobbyMain");
        this.lobbyNet = this.lobbyMain.lobbyNet;
        this.playerInfo = this.lobbyMain.playerInfo;
        this.messageId = 0;
    },

    start() {
        this.maskLength = this.node.getChildByName("mask").width
    },

    update(dt) {
        this.label.x -= 0.5
        if (this.label.x < -(this.maskLength / 2) - (this.label.width / 2) && this.node.opacity) {
            this.label.x = 0
            this.messageId++;
            this.label.getComponent(cc.Label).string = this.playerInfo.message[this.messageId].message;
            if (this.messageId >= this.playerInfo.message.length - 1) {
                this.messageId = 0
            }
        }
    },

    // 从服务器获取消息后
    onGetMessage() {
        this.messageId = 0;
        this.label.getComponent(cc.Label).string = this.playerInfo.message[this.messageId].message;
        this.label.x = 0
        this.node.opacity = 255;
    },

    //跑马灯消息修改了
    onUpdateMessage(data) {
        this.playerInfo.message = data;
        this.messageId = 0;
    },
});
